﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace _053.TCP客户端TcpClient
{
	internal class Program
	{
		static void Main(string[] args)
		{
			Socket tcpClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
			IPAddress iPAddress = new IPAddress(new byte[] { 10, 34, 200, 36 });
			IPEndPoint iPEndPoint = new IPEndPoint(iPAddress, 7788);
			// 连接
			tcpClient.Connect(iPEndPoint);
			Console.WriteLine("连接上服务器端了");

			string message = "我上线了";
			// 转变为字节数组
			tcpClient.Send(Encoding.UTF8.GetBytes(message));

			byte[] data = new byte[1024];
			int length = tcpClient.Receive(data);
			// 二进制变字符
			string tcpServerMessage = Encoding.UTF8.GetString(data, 0, length);
			Console.WriteLine("接受到服务器端消息：" + tcpServerMessage);

			tcpClient.Close();
		}
	}
}
